;*****************************************************
; 	Copyright (C) SEIKO EPSON CORP. 1997-2001
;	All rights Reserved
;
;	File name : strpbrk.s
;	Function  :
;	       This is strpbrk function
;	Revision  :
;		1997/03/25	V.Chan start
;		2001/12/06	T.Tazaki for GNU33(Linux)
;*****************************************************

;*****************************************************
; strpbrk
;	locates first occurrence in src1 (0 terminated)
;	of any character from src2 (0 terminated)
;
; arguments : %r6:src1 addr, %r7:src2 addr
; return    : %r4:addr of first occurrence
; comment   : destroy %r9
;*****************************************************

	.section .text
	.align 1
	.global strpbrk
	.type	strpbrk,@function

strpbrk:
	ld.w	%r4, 0		; initialize as NULL

strpbrk_loop:
	ld.ub	%r10, [%r6]+	; load byte
	cmp		%r10, 0
	jreq	strpbrk_ret
	ld.w	%r11, %r7		; temp = cmp addr

cmp_loop:
	ld.ub	%r9, [%r11]+	; load byte
	cmp		%r9, %r10
	jreq	afterloop
	cmp		%r9, 0		; loop until end of string
	jrne	cmp_loop

	jp		strpbrk_loop

afterloop:
	sub		%r6, 1
	ld.w	%r4, %r6

strpbrk_ret:
	ret

